//
//  ST_MeetYouOfLookMeViewController.swift
//  btvideo
//
//  Created by mac on 2020/8/3.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

/*

import UIKit
import SwifterSwift
import SwiftyJSON
import HandyJSON
import MBProgressHUD
import MJRefresh
import SwiftyAttributes

/**
 看过了我
 */
class ST_MeetYouOfLookMeViewController: UIViewController {

    static let shared = ST_MeetYouOfLoveMeViewController()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        
        automaticallyAdjustsScrollViewInsets = false
        
        view.addSubview(tableView)
        tableView.snp.makeConstraints { (make) in
            make.top.left.bottom.right.equalToSuperview()
        }
        
        view.addSubview(emptyView)
        emptyView.snp.makeConstraints { (make) in
            make.centerX.width.equalToSuperview()
            make.height.equalTo(emptyView.figured_height)
            make.centerY.equalToSuperview().offset( iPhoneXSeries ? -70 : -80)
        }
        
        tableView.backgroundColor = Color.white
        
        timer = Timer.scheduledTimer(timeInterval: 2*60, target: self, selector: #selector(refresh_data), userInfo: nil, repeats: true)
        
        NotificationCenter.default.addObserver(self, selector: #selector(refresh_data), name: Notification.Name.refresh_sweet_heart, object: nil)
        
        
        NotificationCenter.default.addObserver(self, selector: #selector(refresh_data), name: Notification.Name.in_pur_status_success), object: nil)
        
        
    }
    
    fileprivate var timer:Timer?
    
    @objc func refresh_data(){
        
        self.currentPage = 0
        self.request_data()
        
        if FETCH_MEMBER_STATUS() != .subscribe{
            
            self.tableView.tableFooterView = self.footerView
            
        }else{
            
            self.tableView.tableFooterView = nil
        }
        
    }
    
    
    @objc func clear_data(){
        
        UNREAD_LOOK_OF_MEET = 0
        data_array.removeAll()
        
        self.tableView.reloadData()
        self.tableView.mj_footer = nil
        
        self.emptyView.isHidden = self.data_array.count > 0
        self.tableView.isHidden = self.data_array.count < 1
        
        self.tableView.mj_footer?.endRefreshing()
    }
        
    func request_data(){
        
        guard let token = ST_BTUserInfoManager.shared.current_account_info?.token,  token.count > 1 else{
            
            clear_data()
            
            return
        }
        
        
        currentPage += 1
        
        var param = ["page":currentPage,
        "size":pageSize] as [String : Any]
        
        ST_ChatModuleViewController.shared.curr_filter.conver_to_param().forEach { (item) in
            param.updateValue(item.value, forKey: item.key)
        }
        
        
        JVrequest(PH.meetYouListApi,parameters:param, success: { (json) in
            
            let data = json["data"]
            
                
            self.meeting_masking_switch = data["meeting_masking_switch"].boolValue
                
            self.headerView.number = (key:"看过",value:data["total"].intValue)
            
            self.footerView.number = (key:"人看过你呢，立即成为会员解锁看看\n都是谁在悄悄看我吧",value:data["total"].intValue)
           
            if FETCH_MEMBER_STATUS() != .subscribe && self.meeting_masking_switch{
                
                self.tableView.tableFooterView = self.footerView
                
            }else{
                self.tableView.tableFooterView = nil
            }
            
            if ST_ChatModuleViewController.shared.current_display_tab_index() != 2{
                UNREAD_LOOK_OF_MEET = data["meet_num"].intValue
            }else{
                UNREAD_LOOK_OF_MEET = 0
            }
            
            
            let array = data["list"].arrayValue.map { (itemJson) -> ST_MeetYouCellModel in
                return ST_MeetYouCellModel.init(fromJson: itemJson)
            }
            
            print("遇见Array:",data)
        
             if self.currentPage == 1{
                self.data_array = array
             }else{
                self.data_array += array
            }
                
            
            self.tableView.reloadData()
            
//            不是会员但是需要会员
            if FETCH_MEMBER_STATUS() != .subscribe && self.meeting_masking_switch{
                
                self.tableView.mj_footer = nil
                
            }else{
                
                self.load_more_option_style(tableView: self.tableView, count: array.count, pageSize: self.pageSize) {
                    
                    self.tableView.mj_footer = MJRefreshAutoNormalFooter.init(refreshingBlock: {[weak self] in

                        self?.request_data()
                    })
                }
            }
            
            
            
            self.emptyView.isHidden = self.data_array.count > 0
            self.tableView.isHidden = self.data_array.count < 1
            
            self.tableView.mj_footer?.endRefreshing()
            
        }) { (code, err) in
            self.currentPage -= 1
            
            self.tableView.mj_footer?.endRefreshing()
            
            ToastHud(text: err, view: self.view)
        }
        
    }
    
//    MARK:- Properties
    
    var currentPage = 0
    
    
    fileprivate var pageSize = 15
    
    fileprivate lazy var tableView:UITableView = {
        
        let control = UITableView.init(frame: CGRect.zero, style: UITableView.Style.plain)
        
        let bottomEdge = iPhoneXSeries ? BTSafeAreaBottom + 10 : 30
        
        control.contentInset = UIEdgeInsets.init(top: 0, left: 0, bottom: bottomEdge + 49 + 20, right: 0)
        
        control.delegate = self
        
        control.dataSource = self
        
//        control.rowHeight = UITableView.automaticDimension
        
//        control.estimatedRowHeight = 92
        
        control.register(cellWithClass: ST_LookedOfMeetYouCell.self)
        
        control.register(cellWithClass: LookedOfMeetYouVisualEffectCell.self)
        
        control.separatorStyle = .none
        
        control.allowsMultipleSelectionDuringEditing = true
        
        control.backgroundColor = Color.white
        
        control.tableHeaderView = headerView
        //        control.backgroundColor = Color.random
        
        if #available(iOS 11.0, *) {
            control.contentInsetAdjustmentBehavior = .never
        }
        control.showsVerticalScrollIndicator = false
        control.showsHorizontalScrollIndicator = false
        return control
    }()
    
    /**
     为True 需要会员
     */
    fileprivate var meeting_masking_switch = true
    
    fileprivate lazy var headerView:ST_MeetYouHeader = {
            
        let control = ST_MeetYouHeader.init(frame: CGRect.init(x: 0, y: 0, width: ScreenWidth, height: ST_MeetYouHeader.height))
        
        return control
    }()
    
    fileprivate lazy var footerView:MeetYouFooter = {
            
        let control = MeetYouFooter.init(frame: CGRect.init(x: 0, y: 0, width: ScreenWidth, height: MeetYouFooter.height))
        
        return control
    }()
    
    
    fileprivate lazy var emptyView:ST_BTEmptyView = {
        
        let control = ST_BTEmptyView.init(title: "添加更多优质的特质，才会有人来喜欢你呀！", imageName: ST_ImageUtils.imageName("喜欢_img_喜欢(空)")!, btnTitle: "添加特质") {
            
            push_to_push_peculiarity_controller(navigationController: self.navigationController)
        }
        control.isHidden = true
        return control
    }()
    
    fileprivate var data_array = [ST_MeetYouCellModel]()
    
}


extension ST_MeetYouOfLookMeViewController:UITableViewDelegate,UITableViewDataSource{
    
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return data_array.count
    }
    
    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        
        if let iCell = cell as? LookedOfMeetYouVisualEffectCell{
            iCell.create_visual_effect()
        }
        
    }
    
    func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        
        if let iCell = cell as? LookedOfMeetYouVisualEffectCell{
            iCell.remove_visual_effect()
        }
        
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        if FETCH_MEMBER_STATUS() != .subscribe && self.meeting_masking_switch{
            
            
            let cell = tableView.dequeueReusableCell(withClass: LookedOfMeetYouVisualEffectCell.self, for: indexPath)
            
            cell.model = data_array[safe:indexPath.row]
            
            return cell
        }
        
        
        let cell = tableView.dequeueReusableCell(withClass: ST_LookedOfMeetYouCell.self, for: indexPath)
        
        cell.model = data_array[safe:indexPath.row]
        
        cell.ignoreClosure = {[weak self] id in
            
            guard let strongSelf = self else { return }
            
            strongSelf.data_array.removeFirst(where: {$0.accid == id})
            
            strongSelf.emptyView.isHidden = strongSelf.data_array.count > 0
            strongSelf.tableView.isHidden = strongSelf.data_array.count < 1
            strongSelf.tableView.reloadData()
            
        }
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return ST_LookedOfMeetYouCell.height
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        
//        let vc = ST_PairsCenterViewController()
//
//        vc.accid = data_array[indexPath.item]["accid"].stringValue
//
//        let nav = PairsCenterInteractiveNavigationController.init(rootViewController: vc)
//
//        nav.overCurrentContext = true
//
//        GlobalPresent(toController: nav)
        
    }
    
}
*/
